Dependently-Typed Formalisation of Typed Term Graphs
نویسنده
چکیده
The Coconut project [AK09a, AK09b] uses “code graphs” [KAC06], a variant of term graphs in the spirit of “jungles” [HP91, CR93], as intermediate presentation for the generation of highly optimised assembly code. This is currently implemented in Haskell, and we use the Haskell type system in an embedded domain-specific language (EDSL) for creating such code graphs via what appears to be standard Haskell function definitions, with let-definitions introducing sharing, and with functions representing assemblylevel operations constructing hyperedges [AK09a]. However, since Haskell does not support full dependent typing, the intermediate term graph datatype interface, supporting graph navigation, traversal, and manipulation operations, cannot preserve the connection with the Haskell-level typing of the assembly operations. Therefore, although EDSL-created code graphs are well-typed by construction, as certified by the type checker, this does not hold anymore for code graphs that are the result of internal operations. Those internal operations either require separate proof that they preserve well-typedness, or they need to perform run-time checks, at considerable run-time cost. In addition, our code-graph-creation EDSL has a second “simulator” implementation, which turns the EDSL expressions into Haskell functions that implement a “machine simulation”. Since the code graph representation has lost its connection with the Haskell-level typing, it is “unintuitively hard” to use the simulation machinery for code graphs that result from code graph manipulation operations. Mainly for these reasons, we are now exploring implementation of code graphs in a dependently typed programming language, where there is no need to “loose” the type information when moving to a graph representation, and where even stronger assertions about operations on code graphs than just type preservation can be proven inside the implementing system. We start, in Sect. 2, with a quick introduction to the dependently typed programming language (and proof checker) Agda [Nor07]. This is followed by formalisations of set-based mathematical definitions of untyped (Sect. 3) and typed (Sect. 4) term graphs, and then a summary of the gs-monoidal category view on these term graphs in Sect. 5. Finally, we present two formalisations of acyclic term graphs as (differently structured) nested let-expressions (Sections 6 and 7).
منابع مشابه
A Formalisation of a Dependently Typed Language as an Inductive-Recursive Family
It is demonstrated how a dependently typed lambda calculus (a logical framework) can be formalised inside a language with inductiverecursive families. The formalisation does not use raw terms; the welltyped terms are defined directly. It is hence impossible to create ill-typed terms. As an example of programming with strong invariants, and to show that the formalisation is usable, normalisation...
متن کاملRelative Monads Formalised
Relative monads (Altenkirch, Chapman, and Uustalu 2010) are a recent generalisation of ordinary monads to cover similar structures where the underlying functor need not be an endofunctor. Our interest in this generalisation was triggered by some structures from programming theory that, in many ways, are strikingly similar to monads (even respecting the same laws), have similar programming appli...
متن کاملSimply Easy! An Implementation of a Dependently Typed Lambda Calculus
We present an implementation in Haskell of a dependently-typed lambda calculus that can be used as the core of a programming language. We show that a dependently-typed lambda calculus is no more difficult to implement than other typed lambda calculi. In fact, our implementation is almost as easy as an implementation of the simply typed lambda calculus, which we emphasize by discussing the modif...
متن کاملA Tutorial Implementation of a Dependently Typed Lambda Calculus
We present the type rules for a dependently typed core calculus together with a straightforward implementation in Haskell. We explicitly highlight the changes necessary to shift from a simply-typed lambda calculus to the dependently typed lambda calculus. We also describe how to extend our core language with data types and write several small example programs. The article is accompanied by an e...
متن کاملUsability: Formalising (un)deenedness in Typed Lambda Calculus
In this paper we discuss usability, and propose to take that notion as a formalisation of (un)deenedness in typed lambda calculus, especially in calculi based on PCF. We discuss some important properties that make usability attractive as a formalisation of (un)deenedness. There is a remarkable diierence between usability and solvability: in the untyped lambda calculus the solvable terms are pre...
متن کامل